package main

import (
	"fmt"
	"io"
	"os"
	"time"

	"gitee.com/liyp/LFData"
	"gitee.com/liyp/gnet"
)

func main() {

	file, err := os.OpenFile("3jie_zs.json", os.O_RDWR, 066)
	data := make([]byte, 20*1024*1024) //文件的信息可以读取进一个[]byte切片
	count, err := file.Read(data)
	if err != nil {
		if err == io.EOF { //文件结尾
			fmt.Println("文件读取结束")
		}
	}
	fmt.Printf("read %d \n", count)

	// a.AddTable("aaa", -5678901234)
	// var c LFData.LFData
	// c.AddTable("33225", []byte("0123456789\x40\x4a\x4b\x4c\x4d\x4e\x4f\xff\xfa\xcabbccdd"))
	// a.AddTable("bbc", c)

	// r := a.WriteToBuf()
	// var b LFData.LFData
	// b.ReadFromBuf(r)

	// json := b.WriteToJson()
	// fmt.Println(json)
	// fmt.Println("-----------")

	// _, err := a.ReadFromJson("\"\\t\\b\\n\\u6211\"")

	var loopcount int64
	loopcount = 10

	jsonst := string(data[:count])
	tm := time.Now().UnixNano()

	var i int64
	for i = 0; i < loopcount; i++ {
		// println(1234)
		var a LFData.LFData
		_, err = a.ReadFromJson(jsonst)
		if err != nil {
			gnet.Error("read err:%s", err.Error())
			return
		}
	}
	println(123)
	gnet.Success("golang read time:%dms", (time.Now().UnixNano()-tm)/1000000/loopcount)

	var a LFData.LFData
	_, err = a.ReadFromJson(jsonst)
	if err != nil {
		fmt.Println(err.Error())
	} else {
		tm = time.Now().UnixNano()
		for i = 0; i < loopcount; i++ {
			a.WriteToJson()
		}
		gnet.Success("golang write time:%dms", (time.Now().UnixNano()-tm)/1000000/loopcount)
	}

	gnet.WaitClose()
}
